/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef SERVEREVENTPARSER_H
#define SERVEREVENTPARSER_H

#include "serverevents.h"
#include "xmlnode.h"

#include <QXmlStreamWriter>

/*[[[cog
import cog
from servereventdefs import *
]]]
[[[end]]]*/

/**
 * The ServerEventParser class provides static methods for writing ServerEvents into
 * XML streams and reading ServerEvents from XML streams.
 * @author MacJariel
 */
class ServerEventParser
{
public:
    /**
     * Writes ServerEvent into XML stream using QXmlStreamWriter.
     */
    static void write(QXmlStreamWriter*, ServerEventDataPtr);
    /**
     * Reads the ServerEvent from XML stream and returns it.
     */
    static ServerEventDataPtr read(XmlNode*);

private:
    /*[[[cog
    for se in ServerEvents:
        cog.outl("static void write%(serverEventName)s(QXmlStreamWriter*, const %(structName)sPtr&);" % se)
        cog.outl("static %(structName)sPtr read%(serverEventName)s(XmlNode*);" % se)
        cog.outl();
    ]]]*/
    static void writeEnterGame(QXmlStreamWriter*, const EnterGameEventDataPtr&);
    static EnterGameEventDataPtr readEnterGame(XmlNode*);

    static void writeExitGame(QXmlStreamWriter*, const ExitGameEventDataPtr&);
    static ExitGameEventDataPtr readExitGame(XmlNode*);

    static void writeCreatePlayer(QXmlStreamWriter*, const CreatePlayerEventDataPtr&);
    static CreatePlayerEventDataPtr readCreatePlayer(XmlNode*);

    static void writeRemovePlayer(QXmlStreamWriter*, const RemovePlayerEventDataPtr&);
    static RemovePlayerEventDataPtr readRemovePlayer(XmlNode*);

    static void writeChatMessage(QXmlStreamWriter*, const ChatMessageEventDataPtr&);
    static ChatMessageEventDataPtr readChatMessage(XmlNode*);

    static void writeGameUpdate(QXmlStreamWriter*, const GameUpdateEventDataPtr&);
    static GameUpdateEventDataPtr readGameUpdate(XmlNode*);

    //[[[end]]]
};


#endif // SERVEREVENTPARSER_H
